﻿using System;
using System.Windows.Forms;
using Telerik.WinControls.UI.Docking;
using Zvezda.FSO2.DB;
using System.Security.Principal;
using System.Data;
using System.Collections.Generic;

namespace FSO
{
	public partial class MainForm : Form
	{

		DateTime _oldSelectDate;
		DataView userRights;

		public MainForm()
		{
			// Задаем культуру
			System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ru-ru");

			InitializeComponent();

			Telerik.WinControls.UI.Localization.RadGridLocalizationProvider.CurrentProvider =
				new FSO.Localization.RussianRadGridLocalizationProvider();
			Telerik.WinControls.UI.Localization.RadDockLocalizationProvider.CurrentProvider = new FSO.Localization.RussiaDockLocalizationProvidern();
			Telerik.WinControls.UI.RadToolStripLocalizationProvider.CurrentProvider = new FSO.Localization.RussianToolStripLocalizationProvider();

			//скрываем кнопку настройки панели кнопок (сохранить, обновить, удалить)
			radToolStripItem1.OverflowButton.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
		}

		private void radCalendarMain_SelectionChanged(object sender, EventArgs e)
		{
			//Отображение курса валют
			DateTime date;
			//При повторном нажатии на выбранную дату в календаре SelectedDate сбрасывается на RangeMinDate, этот if исправляет последствия данного каcяка
			if (radCalendarMain.SelectedDate == radCalendarMain.RangeMinDate)
			{
				date = _oldSelectDate;
			}
			else
			{
				date = radCalendarMain.SelectedDate;
				_oldSelectDate = date;
			}

			decimal rateDollar = FormHelper.GetRate("USD", date);
			decimal rateEuro = FormHelper.GetRate("EUR", date);

			radLabelDollarIcon.Text = " = " + rateDollar + " руб.";

			radLabelEuroIcon.Text = " = " + rateEuro + " руб.";

		}

		private void MainForm_Load(object sender, EventArgs e)
		{
			//Определяем начальные параметры календаря (тот который справа)
			radCalendarMain.FocusedDate = DateTime.Now.Date;
			radCalendarMain.SelectedDate = DateTime.Now.Date;
			_oldSelectDate = DateTime.Now.Date;
			User_RightsTableAdapter1.Fill(dataSetFSO1.USER_RIGHTS);
			//Указываем главное окно
			FormHelper.MainDock = radDockMain;
			FormHelper.MainForm = this;
			FormHelper.MainDock.ActiveWindowChanged += new DockWindowEventHandler(MainDock_ActiveWindowChanged);
			userRights = dataSetFSO1.USER_RIGHTS.Where(x => x.LOGIN.ToLower() == WindowsIdentity.GetCurrent().Name.ToLower()).AsDataView();
			//userRights = dataSetFSO1.USER_RIGHTS.Where(x => x.LOGIN == "ZVEZDA\\Adrova-A-E").AsDataView();

			if (userRights.Count == 0)
			{
				DataRowView row = userRights.AddNew();
				row["PAY_IN"] = "R";
				row["PAY_OUT"] = "R";
				row["INVOICE_IN"] = "R";
				row["INVOICE_OUT"] = "R";
				row["CALENDAR_PLAN"] = "R";
				row["COST_PROTOCOL"] = "R";
				row["GUILD_BILL"] = "R";
				row["VAT_INV"] = "R";
				row["CONTRACT"] = "R";
				row["ORGANIZATION"] = "R";
			}
		}
		void MainDock_ActiveWindowChanged(object sender, DockWindowEventArgs e)
		{
			var formName = e.DockWindow.Name;
			if (userRights.Count == 0)
				return;
			radButtonElementSave.Enabled = false;
			radButtonElementDelete.Enabled = false;
			if (formName.Contains("InvoiceIn"))
				if (userRights[0]["INVOICE_IN"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("PaymentOut"))
				if (userRights[0]["PAY_OUT"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("InvoiceOut"))
				if (userRights[0]["INVOICE_OUT"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("PaymentIn"))
				if (userRights[0]["PAY_IN"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("VatInvoice"))
				if (userRights[0]["VAT_INV"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("Contract"))
				if (userRights[0]["CONTRACT"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("CalendarPlan"))
				if (userRights[0]["CALENDAR_PLAN"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("CostProtocol"))
				if (userRights[0]["COST_PROTOCOL"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("GuildBill"))
				if (userRights[0]["GUILD_BILL"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
					return;
				}
				else return;
			if (formName.Contains("NSIOrganization"))
				if (userRights[0]["ORGANIZATION"].ToString().Contains("RW"))
				{
					radButtonElementSave.Enabled = true;
					radButtonElementDelete.Enabled = true;
				}
				else return;

			//для других форм блокировка не требуется
			radButtonElementSave.Enabled = true;
			radButtonElementDelete.Enabled = true;

		}

		private void radButtonEditUSD_Click(object sender, EventArgs e)
		{
			// MessageBox.Show(this, radCalendarMain.SelectedDate.ToString(), "Некорректное значение", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

			DialogFormExhangeRateSet dialog = new DialogFormExhangeRateSet("USD", radCalendarMain.SelectedDate);
			dialog.ShowDialog();
			if (dialog.DialogResult == DialogResult.OK)
			{
				decimal rateDollar = FormHelper.GetRate("USD", radCalendarMain.SelectedDate);
				radLabelDollarIcon.Text = " = " + rateDollar + " руб.";
			}
		}

		private void radButtonEditEUR_Click(object sender, EventArgs e)
		{
			DialogFormExhangeRateSet dialog = new DialogFormExhangeRateSet("EUR", radCalendarMain.SelectedDate);
			dialog.ShowDialog();
			if (dialog.DialogResult == DialogResult.OK)
			{
				decimal rateEuro = FormHelper.GetRate("EUR", radCalendarMain.SelectedDate);
				radLabelEuroIcon.Text = " = " + rateEuro + " руб.";
			}
		}

		private void radMenuItemNSICurrency_Click(object sender, EventArgs e)
		{
			FormNSICurrency formNSICurrency = new FormNSICurrency();
			if (!FormHelper.HasOpenedForm(formNSICurrency.FormName))
			{
				formNSICurrency.MdiParent = FormHelper.MainForm;
				formNSICurrency.Show();
				formNSICurrency.Select();
			}
		}

		private void radMenuItemNSIProduct_Click(object sender, EventArgs e)
		{
			FormNSIProduct formNSIProduct = new FormNSIProduct();
			if (!FormHelper.HasOpenedForm(formNSIProduct.FormName))
			{
				formNSIProduct.MdiParent = FormHelper.MainForm;
				formNSIProduct.Show();
				formNSIProduct.Select();
			}
		}
		void radMenuItemNSIProductGroups_Click(object sender, System.EventArgs e)
		{
			FormNSIProductGroup formNSIProductGroup = new FormNSIProductGroup();
			if (!FormHelper.HasOpenedForm(formNSIProductGroup.FormName))
			{
				formNSIProductGroup.MdiParent = FormHelper.MainForm;
				formNSIProductGroup.Show();
				formNSIProductGroup.Select();
			}
		}

		private void radMenuItemNSIMeter_Click(object sender, EventArgs e)
		{
			FormNSIMeter formNSIMeter = new FormNSIMeter();
			if (!FormHelper.HasOpenedForm(formNSIMeter.FormName))
			{
				formNSIMeter.MdiParent = FormHelper.MainForm;
				formNSIMeter.Show();
				formNSIMeter.Select();
			}
		}

		private void radMenuItemNSIMaterial_Click(object sender, EventArgs e)
		{
			FormNSIMaterial formNSIMaterial = new FormNSIMaterial();
			if (!FormHelper.HasOpenedForm(formNSIMaterial.FormName))
			{
				formNSIMaterial.MdiParent = FormHelper.MainForm;
				formNSIMaterial.Show();
				formNSIMaterial.Select();
			}
		}

		private void radMenuItemNSIService_Click(object sender, EventArgs e)
		{
			FormNSIService formNSIService = new FormNSIService();
			if (!FormHelper.HasOpenedForm(formNSIService.FormName))
			{
				formNSIService.MdiParent = FormHelper.MainForm;
				formNSIService.Show();
				formNSIService.Select();
			}
		}

		private void radMenuItemNSITypeOfAct_Click(object sender, EventArgs e)
		{
			FormNSITypeOfAct formNSI_TOA = new FormNSITypeOfAct();
			if (!FormHelper.HasOpenedForm(formNSI_TOA.FormName))
			{
				formNSI_TOA.MdiParent = FormHelper.MainForm;
				formNSI_TOA.Show();
				formNSI_TOA.Select();
			}
		}

		private void radButtonElementSave_Click(object sender, EventArgs e)
		{
			DockWindow dockWindow = radDockMain.ActiveWindow;

			if (dockWindow is HostWindow)
			{
				Form activeForm = ((HostWindow)dockWindow).MdiChild;
				if (activeForm is IntefaceObjectForm)
				{
					((IntefaceObjectForm)activeForm).Save();
				}
			}
		}

		private void radMenuItemNSIProdState_Click(object sender, EventArgs e)
		{
			FormNSIProductState formNSI_ProdState = new FormNSIProductState();
			if (!FormHelper.HasOpenedForm(formNSI_ProdState.FormName))
			{
				formNSI_ProdState.MdiParent = FormHelper.MainForm;
				formNSI_ProdState.Show();
				formNSI_ProdState.Select();
			}
		}

		private void radMenuItemNSIPayDirect_Click(object sender, EventArgs e)
		{
			FormNSIPayDirect formNSI_PayDirect = new FormNSIPayDirect();
			if (!FormHelper.HasOpenedForm(formNSI_PayDirect.FormName))
			{
				formNSI_PayDirect.MdiParent = FormHelper.MainForm;
				formNSI_PayDirect.Show();
				formNSI_PayDirect.Select();
			}
		}

		private void radMenuItemNSIFinRes_Click(object sender, EventArgs e)
		{
			FormNSIFinResource formNSI_FinRes = new FormNSIFinResource();
			if (!FormHelper.HasOpenedForm(formNSI_FinRes.FormName))
			{
				formNSI_FinRes.MdiParent = FormHelper.MainForm;
				formNSI_FinRes.Show();
				formNSI_FinRes.Select();
			}
		}

		private void radMenuItemExpenseItem_Click(object sender, EventArgs e)
		{
			FormNSIExpenseItem formNSI_ExpItem = new FormNSIExpenseItem();
			if (!FormHelper.HasOpenedForm(formNSI_ExpItem.FormName))
			{
				formNSI_ExpItem.MdiParent = FormHelper.MainForm;
				formNSI_ExpItem.Show();
				formNSI_ExpItem.Select();
			}
		}

		private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			//DialogResult result = MessageBox.Show(this, "Вы уверены, что хотите закрыть приложение?", "Закрыть приложение", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
			foreach (Form form in radDockMain.MdiChildren)
			{
				if (form is IntefaceObjectForm)
				{
					form.Close();
				}
			}
		}

		private void radMenuItemTest_Click(object sender, EventArgs e)
		{
			//FormCalendarPlan form = new FormCalendarPlan();
			//if (!form.IsDisposed)
			//{
			//    form.MdiParent = FormHelper.MainForm;
			//    form.Show();
			//    form.Select();
			//}
		}

		private void radMenuItemCreateOrg_Click(object sender, EventArgs e)
		{
			FormNSIOrganization formOrg = new FormNSIOrganization();
			formOrg.MdiParent = FormHelper.MainForm;
			formOrg.AllowSave = userRights[0]["ORGANIZATION"].ToString().Contains("RW");
			formOrg.Show();
			formOrg.Select();
		}

		private void radButtonElementDelete_Click(object sender, EventArgs e)
		{
			DockWindow dockWindow = radDockMain.ActiveWindow;

			if (dockWindow is HostWindow)
			{
				Form activeForm = ((HostWindow)dockWindow).MdiChild;
				if (activeForm is InterfaceObjDeleteableForm)
				{
					DialogResult result;
					result = MessageBox.Show(this, "Данный объект и связанные с ним элементы будут удалены! Продолжить?", "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
					if (result == DialogResult.Yes)
						((InterfaceObjDeleteableForm)activeForm).Delete();
				}
			}
		}

		private void radMenuItemInvoiceIn_Click(object sender, EventArgs e)
		{
			FormInvoiceIn formInvoiceIn = new FormInvoiceIn();
			formInvoiceIn.AllowSave = userRights[0]["INVOICE_IN"].ToString().Contains("RW");
			formInvoiceIn.MdiParent = FormHelper.MainForm;
			formInvoiceIn.Show();
			formInvoiceIn.Select();
		}

		private void radButtonElementRefresh_Click(object sender, EventArgs e)
		{
			DockWindow dockWindow = radDockMain.ActiveWindow;

			if (dockWindow is HostWindow)
			{
				Form activeForm = ((HostWindow)dockWindow).MdiChild;
				if (activeForm is IntefaceObjectForm)
				{
					DialogResult result;
					result = MessageBox.Show(this, "Все несохраненные данные будут утеряны! Продолжить?", "Подтверждение обновления", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
					if (result == DialogResult.Yes)
					{
						((IntefaceObjectForm)activeForm).RefreshForm();
					}
				}
			}
		}

		private void radMenuItemContract_Click(object sender, EventArgs e)
		{
			FormContract formContract = new FormContract();
			formContract.MdiParent = FormHelper.MainForm;
			formContract.AllowSave = userRights[0]["CONTRACT"].ToString().Contains("RW");
			formContract.Show();
			formContract.Select();

		}

		private void radMenuItemPaymentOut_Click(object sender, EventArgs e)
		{
			FormPaymentOut formPayOut = new FormPaymentOut();
			formPayOut.AllowSave = userRights[0]["PAY_OUT"].ToString().Contains("RW");
			formPayOut.MdiParent = FormHelper.MainForm;
			formPayOut.Show();
			formPayOut.Select();
		}

		private void radMenuItemInvoiceOut_Click(object sender, EventArgs e)
		{
			DialogFormSelectObject selectContractForm = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
			DialogResult res = selectContractForm.ShowDialog();
			if (res == DialogResult.OK)
			{
				try
				{
					DataSetFSO.CONTRACTRow contract = (DataSetFSO.CONTRACTRow)selectContractForm.SelectedRow;
					FormInvoiceOut formInvOut = new FormInvoiceOut(contract.PID);
					formInvOut.AllowSave = userRights[0]["INVOICE_OUT"].ToString().Contains("RW");
					formInvOut.MdiParent = FormHelper.MainForm;
					formInvOut.Show();
					formInvOut.Select();
				}
				catch { }
			}
		}

		//private void radMenuItemSearchProductUnit_Click(object sender, EventArgs e)
		//{
		//    FormSearchProductUnit formSearch = new FormSearchProductUnit();
		//    formSearch.MdiParent = FormHelper.MainForm;
		//    formSearch.Show();
		//    formSearch.Select();
		//}

		private void radMenuItemCostProtocol_Click(object sender, EventArgs e)
		{
			DialogFormSelectObject selectContractForm = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
			DialogResult res = selectContractForm.ShowDialog();
			if (res == DialogResult.OK)
			{
				DataSetFSO.CONTRACTRow contract = (DataSetFSO.CONTRACTRow)selectContractForm.SelectedRow;
				FormCostProtocol formCostProtocol = new FormCostProtocol(contract.PID);
				formCostProtocol.AllowSave = userRights[0]["COST_PROTOCOL"].ToString().Contains("RW");
				formCostProtocol.MdiParent = FormHelper.MainForm;
				formCostProtocol.Show();
				formCostProtocol.Select();
			}
		}

		private void radMenuItemPayIn_Click(object sender, EventArgs e)
		{
			DialogFormSelectObject selectContractForm = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
			DialogResult res = selectContractForm.ShowDialog();
			if (res == DialogResult.OK)
			{
				DataSetFSO.CONTRACTRow contract = (DataSetFSO.CONTRACTRow)selectContractForm.SelectedRow;

				FormPaymentIn formPayIn = new FormPaymentIn(contract.PID);
				formPayIn.AllowSave = userRights[0]["PAY_IN"].ToString().Contains("RW");
				formPayIn.MdiParent = FormHelper.MainForm;
				formPayIn.Show();
				formPayIn.Select();
			}
		}

		private void radMenuItemDirect_Click(object sender, EventArgs e)
		{
			DialogFormSelectObject selectContractForm = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
			DialogResult res = selectContractForm.ShowDialog();
			if (res == DialogResult.OK)
			{
				DataSetFSO.CONTRACTRow contract = (DataSetFSO.CONTRACTRow)selectContractForm.SelectedRow;
				FormDirect formDirect = new FormDirect(contract.PID);
				formDirect.MdiParent = FormHelper.MainForm;
				formDirect.Show();
				formDirect.Select();
			}
		}
		/// <summary>
		/// Обрабатывает нажатие на пункт главного меню Отчеты -> Полученные средства
		/// </summary>
		private void radMenuItemReceivedMeans_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm("/Zvezda2.Reports/ReceivedMeans"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlRecievedMeansParams), Properties.Settings.Default.ReportServerFolder + "/ReceivedMeans", "Полученные средства");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
		/// <summary>
		/// Обрабатывает нажатие на пункт главного меню Отчеты -> Неоплаченные входящие счета
		/// </summary>
		private void radMenuItemNotPayedInputInvoices_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/NotPayedInputInvoices"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlNotPayedInputInvoicesParams), Properties.Settings.Default.ReportServerFolder + "/NotPayedInputInvoices", "Неоплаченные входящие счета");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
		/// <summary>
		/// Обрабатывает нажатие на пункт главного меню Отчеты -> Оплаченные входящие счета
		/// </summary>
		private void radMenuItemPayedInputInvoices_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/PayedInputInvoices"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlPayedInputInvoicesParams), Properties.Settings.Default.ReportServerFolder + "/PayedInputInvoices", "Оплаченные входящие счета");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}

		private void radMenuItemGuildBill_Click(object sender, EventArgs e)
		{
			DialogFormSelectObject selectContractForm = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
			DialogResult res = selectContractForm.ShowDialog();
			if (res == DialogResult.OK)
			{
				DataSetFSO.CONTRACTRow contract = (DataSetFSO.CONTRACTRow)selectContractForm.SelectedRow;
				FormGuildBill formGuilBill = new FormGuildBill(contract.PID);
				formGuilBill.AllowSave = userRights[0]["GUILD_BILL"].ToString().Contains("RW");
				formGuilBill.MdiParent = FormHelper.MainForm;
				formGuilBill.Show();
				formGuilBill.Select();
			}
		}

		private void radMenuItemVatInvoice_Click(object sender, EventArgs e)
		{
			DialogFormSelectObject selectContractForm = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
			DialogResult res = selectContractForm.ShowDialog();
			if (res == DialogResult.OK)
			{
				DataSetFSO.CONTRACTRow contract = (DataSetFSO.CONTRACTRow)selectContractForm.SelectedRow;
				FormVatInvoice formVatInvoice = new FormVatInvoice(contract.PID);
				formVatInvoice.AllowSave = userRights[0]["VAT_INV"].ToString().Contains("RW");
				formVatInvoice.MdiParent = FormHelper.MainForm;
				formVatInvoice.Show();
				formVatInvoice.Select();
			}
		}

		private void radMenuItemPayService_Click(object sender, EventArgs e)
		{
			//У данного платежа нет связанного договора
			int? pid = null;
			FormPaymentIn formPayIn = new FormPaymentIn(pid);
			formPayIn.MdiParent = FormHelper.MainForm;
			formPayIn.Show();
			formPayIn.Select();
		}

		private void radMenuItemVatInvServices_Click(object sender, EventArgs e)
		{
			int? pid = null;
			FormVatInvoice formVatInv = new FormVatInvoice(pid);
			formVatInv.MdiParent = FormHelper.MainForm;
			formVatInv.Show();
			formVatInv.Select();
		}

		private void radMenuItemCalendarPlan_Click(object sender, EventArgs e)
		{
			DialogFormSelectObject selectContractForm = new DialogFormSelectObject(ObjctTypeEnum.CONTRACT);
			DialogResult res = selectContractForm.ShowDialog();
			if (res == DialogResult.OK)
			{
				DataSetFSO.CONTRACTRow contract = (DataSetFSO.CONTRACTRow)selectContractForm.SelectedRow;
				FormCalendarPlan formCalendarPlan = new FormCalendarPlan(contract.PID);
				formCalendarPlan.AllowSave = userRights[0]["CALENDAR_PLAN"].ToString().Contains("RW");
				formCalendarPlan.MdiParent = FormHelper.MainForm;
				formCalendarPlan.Show();
				formCalendarPlan.Select();
			}
		}
		/// <summary>
		/// Отчеты -> Полученные счета по исходящим счетам
		/// </summary>
		private void radMenuItemReceivedMeansOutInvoice_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/ReceivedMeansOutInvoices"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlRecievedMeansOutInvoiceParams), Properties.Settings.Default.ReportServerFolder + "/ReceivedMeansOutInvoices", "Полученные средства по исходящим счетам");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}

		private void radMenuItemInvoiceService_Click(object sender, EventArgs e)
		{
			int? pid = null;
			FormInvoiceOut formInvOut = new FormInvoiceOut(pid);
			formInvOut.MdiParent = FormHelper.MainForm;
			formInvOut.Show();
			formInvOut.Select();
		}
		/// <summary>
		/// Отчеты -> Выставленные счета
		/// </summary>
		private void radMenuItemReportExposedAdvice_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/ExposedAdvance"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlExposedAdvanceParams), Properties.Settings.Default.ReportServerFolder + "/ExposedAdvance", "Выставленные авансы");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
		/// <summary>
		/// Отчеты -> Задолженности основных заказчиков
		/// </summary>
		private void radMenuItemReportDebtPrincipalCustomers_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/DebtPrincipalCustomers"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlDebtPrincipalCustomersParams), Properties.Settings.Default.ReportServerFolder + "/DebtPrincipalCustomers", "Задолженности основных заказчиков");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
		/// <summary>
		/// Отчеты -> Оплаченные изделия
		/// </summary>
		private void radMenuItemPaidMaterials_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/PaidProducts"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlPaidMaterialsParams), Properties.Settings.Default.ReportServerFolder + "/PaidProducts", "Оплаченные изделия");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
		/// <summary>
		/// Отчеты -> Долги производства
		/// </summary>
		private void radMenuItemManufactureDebts_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/ManufactureDebts"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlManufactureDebtsParams), Properties.Settings.Default.ReportServerFolder + "/ManufactureDebts", "Долги производства");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
		/// <summary>
		/// Отчеты -> Счета-фактуры
		/// </summary>
		private void radMenuItemReportVatInvoices_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/VATInvoices"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlVatInvoicesParams), Properties.Settings.Default.ReportServerFolder + "/VATInvoices", "Счета-фактуры");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
		/// <summary>
		/// Отчеты -> Отгруженные изделия
		/// </summary>
		private void radMenuItemReportShipedProducts_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/ShippedProducts"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlShipedProductsParams), Properties.Settings.Default.ReportServerFolder + "/ShippedProducts", "Отгруженные изделия");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
		/// <summary>
		/// Отчеты -> Наличие товаров на складе
		/// </summary>
		private void radMenuItemReportProductsInStock_Click(object sender, EventArgs e)
		{
			if (!FormHelper.HasOpenedForm(Properties.Settings.Default.ReportServerFolder + "/ProductsInStock"))
			{

				FormReport frmReport = new FormReport(typeof(Reports.UserControlProductsInStokParams), Properties.Settings.Default.ReportServerFolder + "/ProductsInStock", "Наличие товаров на складе");
				frmReport.MdiParent = this;
				frmReport.Show();
			}
		}
	}
}
